<template>
  <div class="page-container">
    <div class="common-content-wrap">
      <TrTable
        isNeedSelection
        v-model="searchParams"
        :btnList="btnList"
        :searchShowList="searchShowList"
        :searchHideList="searchHideList"
        :tableData="tableData"
        :tableColumn="tableColumn"
        :total="totalNum"
        requestName="getListHandle"
        @rowSync="operateHandle($event, 'rowSync')"
        @sync="operateHandle($event, 'sync')"
        @view="operateHandle($event, 'view')"
      />
    </div>
  </div>
</template>

<script>
import { getList, getBizMould } from "@/api/system/synchronous";
import { getColor } from "@/utils/billColor";
import TrTable from "@/components/Tr-table/Tr-table.vue";
export default {
  name: "synchronousBox",
  components: {
    TrTable,
  },
  data: () => ({
    totalNum: 0,
    tableData: [],
    searchParams: {
      current: 1,
      size: 10,
    },
    btnList: [
      {
        label: "同步",
        option: "sync",
        color: "blue",
        isRelaTable: true,
      },
    ],
    searchShowList: [
      {
        isNeed: true,
        startStr: "billCreateTimeStart",
        endStr: "billCreateTimeEnd",
        id: "createdTime",
        type: "daterange",
        width: 80,
        label: "单据创建时间",
        value: [],
        timePeriod: true,
        radio: 1,
      },
    ],
    searchHideList: [
      {
        label: "单据号",
        type: "input",
        width: 33.3,
        value: "",
        id: "docCode",
      },
      {
        label: "同步状态",
        type: "multiSelect",
        width: 33.3,
        value: [],
        id: "stateList",
      },
      {
        label: "同步结果",
        type: "multiSelect",
        width: 33.3,
        value: [],
        id: "syncStateList",
      },
      {
        label: "单据类型",
        type: "multiSelect",
        width: 33.3,
        value: [],
        id: "billType",
      },
      {
        startStr: "updateTimeStart",
        endStr: "updateTimeEnd",
        id: "zwTime",
        type: "daterange",
        width: 80,
        label: "账务时间",
        value: [],
        timePeriod: true,
        radio: -1,
      },
    ],
    tableColumn: [
      {
        type: "text",
        label: "单据号",
        value: "docCode",
      },
      {
        type: "text",
        label: "同步状态",
        value: "syncStateName",
      },
      {
        type: "text",
        label: "同步结果",
        value: "stateName",
      },
      {
        type: "text",
        label: "同步次数",
        value: "syncFrequency",
      },
      {
        type: "text",
        label: "单据类型",
        value: "billTypeName",
      },
      {
        type: "text",
        label: "单据创建时间",
        value: "billCreateTime",
      },
      {
        type: "text",
        label: "财务时间",
        value: "updateTime",
      },
      {
        type: "option",
        label: "操作",
        fixed: "right",
        width: 120,
        showBtnList: [
          {
            label: "查看",
            option: "view",
          },
          {
            label: "同步",
            option: "rowSync",
          },
        ],
      },
    ],
  }),
  methods: {
    async initHandle() {
      const typeRes = await this.$fetchEnumApi("mes-warehouse-service", [
        "BizBillTypeEnum",
        "U9SyncMsgStateEnum",
        "U9SyncMsgSyncStateEnum",
      ]);
      const typeCol = this.$findByProperty(
        this.searchHideList,
        "id",
        "billType"
      );
      this.$set(typeCol, "list", typeRes["BizBillTypeEnum"]);
      const stateCol = this.$findByProperty(
        this.searchHideList,
        "id",
        "stateList"
      );
      this.$set(stateCol, "list", typeRes["U9SyncMsgStateEnum"]);
      const resultCol = this.$findByProperty(
        this.searchHideList,
        "id",
        "syncStateList"
      );
      this.$set(resultCol, "list", typeRes["U9SyncMsgSyncStateEnum"]);
    },
    operateHandle(val, type) {
      console.log(val, type, ">>>>>>>>>.");
    },
    getListHandle() {
      getList(this.searchParams).then((res) => {
        if (res.data.code != 200) return this.$message.error(res.data.msg);
        console.log(res, "00000000000000000000");
        let data = res.data.data;
        this.$validateData(data);
        this.totalNum = data.total;
        this.tableData = data.records;
        this.tableData.forEach((item) => {
          item["exportStatusNameColor"] = getColor("RQCX", item.exportStatus);
          item["isShowdown"] = item.exportStatus != 30;
        });
      });
    },
    async getBizMouldHandle() {
      const res = await getBizMould();
      let list = res.data.data.records.map((item) => {
        return {
          label: item.bizMouldName,
          value: item.id,
        };
      });
      const hCol = this.$findByProperty(
        this.searchShowList,
        "id",
        "taskIdList"
      );
      this.$set(hCol, "list", list);
    },
  },
  mounted() {
    // this.getBizMouldHandle();
    this.initHandle();
  },
};
</script>

<style></style>
